// $Id$

using System;
using Salamanca.DataActivities;

namespace Northwind.Activities.OrderCreateNew
{

    internal static class NextStateProvider<TActivityData>
        where TActivityData:
            IData
    {
        public static ActivityState<TActivityData> CreateCustomerAskInfosState(TActivityData data, IParameters parameters)
        {
            return new DomainModel.Activities.CustomerAskInfos<TActivityData, IQuestionFactory>(
                data,
                parameters,
                delegate(TActivityData d, IActivityParameters p) {
                    return _CreateOrderCreateState(d, (IParameters)p);
                }
            );
        }

        private static ActivityState<TActivityData> _CreateOrderCreateState(TActivityData data, IParameters parameters)
        {
            return new OrderCreate<TActivityData>(
                data,
                parameters,
                delegate(TActivityData d, IActivityParameters p) {
                    return _CreateOrderAskInfosState(d, (IParameters)p);
                }
            );
        }

        private static ActivityState<TActivityData> _CreateOrderAskInfosState(TActivityData data, IParameters parameters)
        {
            return new DomainModel.Activities.OrderAskInfos<TActivityData, IQuestionFactory>(
                data,
                parameters,
                delegate(TActivityData d, IActivityParameters p) {
                    return _CreateOrderSaveState(d, (IParameters)p);
                }
            );
        }

        private static ActivityState<TActivityData> _CreateOrderSaveState(TActivityData data, IParameters parameters)
        {
            return new DomainModel.Activities.OrderSave<TActivityData>(data, parameters);
        }
    }

    internal class OrderCreate<TActivityData>:
        DomainModel.Activities.OrderCreate<TActivityData>
        where TActivityData:
            IData
    {
        public OrderCreate(TActivityData data, IParameters parameters, NextStateCreateHandler<TActivityData> nextStateCreator):
            base(data, parameters, nextStateCreator)
        {
        }

        protected override ActivityStateResult Handle(IActivityController controller)
        {
            base.Handle(controller);

            Data.Order.Customer=Data.Customer;

            return ActivityStateResult.Next;
        }
    }

}
